import api from '../../modules/api';



export default {
    namespaced:true,
    state:{
            pageSize:5,
            currentPage:1,
            total:1,
            pages:1,
            type:'',
            value:'',  
    },
    mutations: {
        //---------------------------------保存后端响应的数据(数据的总数和页数)-----------------------
        setPages(state,newDate){
            state.total=newDate.total;
            state.pages=newDate.pages;
        },
        //------------------------------------每页显示几条信息-----------------------------------------
        setPageSize(state,newData){
            // console.log(newData)
            state.pageSize=newData;
            state.currentPage = 1 ;
        },
        //-------------------------------------设置当前页数-----------------------------------------
        setCurrentPage(state,newData){
            state.currentPage=newData
        },
    },
    actions:{
        //----------------------------------获取学生列表---------------------------------------
        async getStudents(context,user){
            
            const {type,value} = {...user} ;
            if(value){
                context.state.currentPage = 1 ;
            }
            const data = await api.students.getStudents({
                type,
                value,
                pageSize:context.state.pageSize,
                currentPage:context.state.currentPage,
            });
            if(data.code){
                context.commit('setPages',data.data)
            }
            return data
        },
        //----------------------------------获取一个学生信息-----------------------------------
        async getStudentsById(context,_id){
            const data = await api.students.getStudentsById(_id);
            return data
        },
        //----------------------------------新增学生信息----------------------------------------
        async addStudents(context,student){
            const data = await api.students.addStudents(student);
            return data
        },
        //----------------------------------删除一条学生信息--------------------------------------
        async deleteStudents(context,_id){
            const data = await api.students.deleteStudents(_id);
            return data
        },
        //----------------------------------修改学生信息------------------------------------------
        async updateStudents(context,newData){
            console.log(newData)
            const data = await api.students.updateStudents(newData);
            return data
        },
        
    },
    
}



















